package com.bw.liuyushan.liuyushan20210929.MVP.Fragment;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.bw.liuyushan.liuyushan20210929.Adapter.TableFragmentAdapter;
import com.bw.liuyushan.liuyushan20210929.MVP.Activity.ZxingActivity;
import com.bw.liuyushan.liuyushan20210929.MVP.Contrack.IContrackTest;
import com.bw.liuyushan.liuyushan20210929.MVP.Model.BaseModelTest;
import com.bw.liuyushan.liuyushan20210929.MVP.Presenter.BasePresenterTest;
import com.bw.liuyushan.liuyushan20210929.R;
import com.bw.liuyushan.mvp_lib.View.BaseFragment;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;

/**
 * Liuyushan20210929
 * file name is : HomeFragment
 * created by Ender on 2021/9/29 14:00.
 * author : 刘雨杉
 * Describe:
 */
public class HomeFragment extends BaseFragment<BasePresenterTest> implements IContrackTest.C_ViewTest {
    private ImageView zx;
    private ImageView talks;
    private TabLayout tabHoume;
    private ViewPager vpHome;
    ArrayList<Fragment> fragments;
    ArrayList<String> strings;



    @Override
    public int bindLayout() {
        return R.layout.fragment_home;
    }

    @Override
    public void initView() {
        //防止内存泄露
        mPresenter = new BasePresenterTest(new BaseModelTest(), this);

        zx = (ImageView) findViewById(R.id.zx);
        talks = (ImageView) findViewById(R.id.talks);
        tabHoume = (TabLayout) findViewById(R.id.tab_houme);
        vpHome = (ViewPager) findViewById(R.id.vp_home);
    }

    @Override
    public void initDate() {
        zx.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), ZxingActivity.class);
                startActivity(intent);
            }
        });
        initTabFragment();
        TableFragmentAdapter tableFragmentAdapter = new TableFragmentAdapter(getChildFragmentManager(), fragments, strings);
        vpHome.setAdapter(tableFragmentAdapter);
        tabHoume.setupWithViewPager(vpHome);

    }

    private void initTabFragment() {
        fragments = new ArrayList<>();
        strings = new ArrayList<>();
        strings.add("有货");
        strings.add("上装");
        strings.add("裤装");
        strings.add("新品");
        strings.add("潮流");
        strings.add("潮流");
        strings.add("潮流");
        strings.add("潮流");
        strings.add("潮流");
        strings.add("潮流");
        strings.add("潮流");
        for (int i = 0; i <strings.size() ; i++) {
                fragments.add(new TabFragment());
        }
    }
}
